package logic

import (
	"context"
	"fmt"
	"order_srv/model/mysql"

	"order_srv/internal/svc"
	"order_srv/order"

	"github.com/zeromicro/go-zero/core/logx"
)

type LoginLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginLogic {
	return &LoginLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *LoginLogic) Login(in *order.LonginRequest) (*order.LonginResponse, error) {
	// todo: add your logic here and delete this line
	var user = mysql.User{}
	err := user.Find(in.Username)
	if err != nil {
		return nil, err
	}
	if user.Password != in.Password {
		return nil, fmt.Errorf("密码不正确")
	}

	return &order.LonginResponse{UserId: int64(user.ID)}, nil
}
